home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / srefv12i.zip / usercfg.cmd < prev    next >
OS/2 REXX Batch file  |  1997-03-21  |  16KB  |  421 lines

  1. /*   */
  2. usercfg:
  3.  
  4. CHECKIT=0   /* Change this to 0 if you want to enable REMOTE configuration by SUPERUSERS */
  5. USECOLOR='2dd52f'
  6.  
  7. /* ---------------- DO NOT MODIFY BELOW THIS LINE  ------------------ */
  8.  
  9.  
  10. parse arg ddir,tempfile,sel,list,verb,uri,user,basedir,workdir,privset,enmadd,transaction,verbose
  11.  
  12. if verb="" then do
  13.    say " This SRE-Filter add-on is NOT meant to be run from the command line."
  14.    say " It can be invoked by using CONFIGUR.HTM "
  15.    exit
  16. end  /* Do */
  17.  
  18.  
  19. list=translate(list, ' ', '+'||'090a0d'x)  /* Whitespace, etc. */
  20.  
  21. who2=extract('CLIENTADDR')
  22. saddr2=extract('SERVERADDR')
  23.  
  24. select
  25.    when checkit=1 then do
  26.  
  27. /* only if user = serveraddress !!! */
  28.      if who2<>saddr2 then do
  29.  
  30.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  31.         call lineout tempfile, "<html><head><title>SREFILTER ERROR </title>"
  32.         call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'"> '
  33.  
  34.         call lineout tempfile,' <strong> Action not allowed remotely.</strong> <pre>'
  35.         call lineout tempfile,' </body> </html> '
  36.         call lineout tempfile
  37.         'FILE ERASE TYPE text/html NAME' tempfile
  38.         return 'USERCFG: action not allowed remotely. '
  39.      end
  40.    end
  41.    otherwise do
  42.       if wordpos('SUPERUSER',privset)=0 then do
  43.        'RESPONSE HTTP/1.0 401 Unauthorized '     /* Set HTTP response line */
  44.        'header add WWW-Authenticate: Basic Realm=<CONFIGURE>'  /* challenge */
  45.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  46.         call lineout tempfile, "<html><head><title>Not authorized </title>"
  47.         call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'"> '
  48.  
  49.         call lineout tempfile,' <strong> You do not have configuration rights.</strong> <pre>'
  50.         if who2=saddr2 then 
  51.                 call lineout tempfile,'<br> <Em> You may want to edit USERCFG.CMD </em> '
  52.         call lineout tempfile,' </body> </html> '
  53.         call lineout tempfile
  54.          iia=dosdir(tempfile,'s')
  55.         'FILE ERASE TYPE text/html NAME' tempfile
  56.         return '401 'iia' USERCFG: not permitted to configure. '
  57.       end
  58.    end
  59. end
  60.  
  61.  
  62.  
  63. list=strip(list)
  64. select 
  65.    when upper(list)='TODO=SHOW' | upper(list)='TODO=SHOW_HEADER' then
  66.         signal doshow
  67.    when upper(list)='TODO=SET' then
  68.         signal doset
  69.    otherwise
  70.         signal dochange
  71. end  /* select */
  72.  
  73. /* jump here to show values */
  74. doshow:
  75. userfile=value(enmadd||'USER_FILE',,'os2environment')
  76. aa=fileread(userfile,'lins',,'E')
  77.  
  78.  
  79.    call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  80.    call lineout tempfile, "<html><head><title>SRE-Filter: view users </title>"
  81.     call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'"> '
  82.    
  83.  
  84.  
  85. call lineout tempfile, "<h1> SRE-Filter: view users        </h1> <p>"
  86. call lineout tempfile, "<h2> List of "header" comments </h2> <pre> <blockquote>"
  87.  
  88. /* show "header comments" */
  89. iat=0
  90. do until iat >= lins.0
  91.    iat=iat+1
  92.    if  abbrev(strip(lins.iat),';')  then do
  93.         foo=strip(lins.iat) ;foo=strip(foo,'l',';')
  94.          call lineout tempfile, foo 
  95.    end  /* Do */
  96.    else do
  97.         leave
  98.    end
  99. end /* do -- iat is the first non header comment line  */
  100. call lineout tempfile, '</blockquote></pre> '
  101.  
  102. /* view descriptive header only? */
  103. if upper(list)='TODO=SHOW_HEADER' then do
  104.    call lineout tempfile,' <hr> </body></html>'
  105.    call lineout tempfile
  106.    'file erase  type text/html name  ' tempfile
  107.    return ' done '
  108. end  /* Do */
  109.  
  110.  
  111.  
  112. /* read in usernames, etc */
  113. nusers=0
  114. call lineout tempfile, ' <hr> <h2> List of users </h2>  '
  115.  
  116. call lineout tempfile,'Notes: <ul> <li> Usernames/passwords are stored in: 'userfile
  117. call lineout tempfile,' <li> <em>Comments are in italics </em> '
  118. call lineout tempfile,' <li>  A <strong>* </strong> in the username or password signifies that <em>any entry is a match </em>'
  119. call lineout tempfile, ' <li> Entries with no <strong>host nickname</strong> apply to all requests</ul> <br>'
  120.  
  121. call lineout tempfile,' <table border=1> <th> Host Nickname </th>'
  122. call lineout tempfile,' <th> Username  </th>'
  123. call lineout tempfile,'  <th> Password </th>'
  124. call lineout tempfile,'  <th> Privileges list </th> <tr>'
  125.  
  126. do mm=iat to lins.0
  127.   if lins.mm=' ' then iterate
  128.   if  abbrev(strip(lins.mm),';') | lins.mm=' ' then do  
  129.        call lineout tempfile,'<td colspan=4>  <code>     </code> <em>' strip(strip(lins.mm),'l',';') '</em></td> <tr> '
  130.  
  131.   end
  132.   else do
  133.       if pos('//',lins.mm)>0 then
  134.            parse var lins.mm hostname '//' username password privs
  135.       else do
  136.            hostname=' .. '
  137.            parse var lins.mm username password privs
  138.       end  /* Do */
  139.       privs=strip(privs)
  140.       call lineout tempfile,'<td> <STRONG> 'hostname ' </STRONG></td>'
  141.       call lineout tempfile,'<td> <STRONG> 'username ' </STRONG></td>'
  142.       call lineout tempfile,'<td> <STRONG> ' password ' </STRONG></td>'
  143.       call lineout tempfile,'<td> <STRONG> ' privs  ' </STRONG></td> <tr>'
  144.   end /* do */
  145.  
  146. end
  147. call lineout tempfile,' </table>'
  148.  
  149.  
  150.  
  151.  
  152. call lineout tempfile,' <hr> Thanks for checking </body></html>'
  153. call lineout tempfile
  154.  
  155. foo=sref_expire_response(0.05,dosdir(tempfile))
  156.  
  157. 'file erase  type text/html name  ' tempfile
  158. return ' done '
  159.  
  160. /* jump here if "set values" chosen */
  161. doset:
  162. userfile=value(enmadd||'USER_FILE',,'os2environment')
  163. aa=fileread(userfile,'lins',,'E')
  164.  
  165. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  166. call lineout tempfile, "<html><head><title>SRE-Filter: modify  users list </title>"
  167. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'"> '
  168.  
  169. /* ignore header stuff */
  170. iat=0
  171. do until iat >= lins.0
  172.    iat=iat+1
  173.    if  abbrev(strip(lins.iat),';') | lins.iat=' ' then iterate
  174.    leave
  175. end /* do -- iat is the first non header comment line  */
  176. call lineout tempfile, "<h1> SRE-Filter: <A NAME="top">modify users list</A>  </h1> <p>"
  177. call lineout tempfile,' <blockquote> You can modify, remove, or add usernames, passwords, and privileges.'
  178. call lineout tempfile,' <br><em> Questions? <A HREF="#notes">The notes might help.</A> </em> </blockquote> '
  179. call lineout tempfile,' <h2> Modify or remove current users </h2>'
  180. call lineout tempfile,'<FORM ACTION="/usercfg" METHOD="GET">'
  181. call lineout tempfile,' <table border=1> <th> Host Nickname <br> (see <A HREF="#hosts">below</A>  for a <br>listing of current hosts) </th>'
  182. call lineout tempfile,' <th> Username  <br> (set to blank to  <br> delete the entry)</th>'
  183. call lineout tempfile,'  <th> Password </th>'
  184. call lineout tempfile,' <th> Superuser and <br>  INHOUSE privileges </th> '
  185. call lineout tempfile,'  <th> Space delimited list  of <br> other privileges </th> <tr>'
  186.  
  187. nhidden=0 ; mm=0
  188. do mm0=iat to lins.0
  189.     alin=translate(lins.mm0,' ','1a000d0a'x)
  190.     mm=mm+1
  191.     if  abbrev(strip(alin),';')=1 | alin=' ' then do
  192.         nhidden=nhidden+1
  193.         hiddens.nhidden='<INPUT TYPE="HIDDEN" name="COMMENT.'||mm||'"  value="'||alin||'" >'
  194.         iterate
  195.     end
  196.  
  197. /* non comment */
  198.     if pos('// ',alin)>0 then
  199.              parse var alin hostname '//' username password privs
  200.         else do
  201.              hostname='  '
  202.              parse var alin username password privs
  203.      end  /* Do */
  204.      call lineout tempfile,'<td> <EM>Host nickname:</EM> <br> <INPUT TYPE="text" NAME="hostname.'||mm||'"'
  205.      call lineout tempfile,'value="'hostname'" SIZE=8 MAXLENGTH=15> </td> '
  206.      call lineout tempfile,'<td> <EM>Username:</EM> <br> <INPUT TYPE="text" NAME="username.'||mm||'"'
  207.      call lineout tempfile,'value="'username'" SIZE=8 MAXLENGTH=15> </td> '
  208.      call lineout tempfile,'<td> <EM>Password:</EM> <br> <INPUT TYPE="text" NAME="password.'||mm||'"'
  209.      call lineout tempfile,'value="'password'" SIZE=8 MAXLENGTH=15> </td> '
  210.  
  211.      privs=strip(privs)
  212.      joe=wordpos('SUPERUSER',upper(privs))
  213.      issuper=0
  214.      if joe>0 then   do
  215.             issuper=1 ;   privs=delword(privs,joe,1)
  216.      end
  217.      inhouse=0
  218.      joe=wordpos('INHOUSE',upper(privs))
  219.      if joe>0 then  do
  220.             inhouse=1 ;   privs=delword(privs,joe,1)
  221.      end
  222.      call lineout tempfile,'  <td> <INPUT TYPE=CHECKBOX NAME="SUPERUSER.'mm||'" '
  223.      if issuper=1 then do
  224.           call lineout tempfile,' CHECKED > SUPERUSER? <br> '
  225.      end
  226.      else
  227.          call lineout tempfile,' >  SUPERUSER? <br> '
  228.      call lineout tempfile,' <INPUT TYPE=CHECKBOX NAME="INHOUSE.'mm||'" '
  229.      if inhouse=1 then do
  230.           call lineout tempfile,' CHECKED > INHOUSE ?</td>  '
  231.      end
  232.      else
  233.          call lineout tempfile,' >  INHOUSE?</td> '
  234.  
  235.      if privs='' then privs=' '
  236.      call lineout tempfile,'<td> <em>Other privileges: </em><br> <INPUT TYPE="text" NAME="privs.'||mm||'"'
  237.      call lineout tempfile,'value="'privs'" SIZE=10 MAXLENGTH=45> </td>  '
  238.      if mm0<lins.0 then do
  239.            call lineout tempfile,'<tr>' ; call lineout tempfile,' '
  240.      end
  241. end
  242. call lineout tempfilem,' '
  243.  
  244. /* --- allow user to enter a few new names */
  245. call lineout tempfile,' </table>  <p> <h2> Add new users </h2> <table border=1>'
  246. mm0=mm
  247. do mm=mm0+1 to mm0+3
  248.      call lineout tempfile,'<td> <EM>Host nickname:</EM> <br> <INPUT TYPE="text" NAME="hostname.'||mm||'"'
  249.      call lineout tempfile,'value=" " SIZE=8 MAXLENGTH=15> </td> '
  250.      call lineout tempfile,'<td> <EM>Username:</EM> <br> <INPUT TYPE="text" NAME="username.'||mm||'"'
  251.      call lineout tempfile,'value=" " SIZE=8 MAXLENGTH=15> </td> '
  252.      call lineout tempfile,'<td> <EM>Password:</EM> <br> <INPUT TYPE="text" NAME="password.'||mm||'"'
  253.      call lineout tempfile,'value=" " SIZE=8 MAXLENGTH=15> </td> '
  254.      call lineout tempfile,'  <td> <INPUT TYPE=CHECKBOX NAME="SUPERUSER.'mm||'"> SUPERUSER? <br> '
  255.      call lineout tempfile,'       <INPUT TYPE=CHECKBOX NAME="INHOUSE.'mm||'"> INHOUSE? </td> '
  256.      call lineout tempfile,'<td> <em>Other privileges: </em><br> <INPUT TYPE="text" NAME="privs.'||mm||'"'
  257.      call lineout tempfile,'value=" " SIZE=10 MAXLENGTH=45> </td>'
  258.      if mm<mm0+3 then call lineout tempfile,' <tr> '
  259. end
  260.  
  261. call lineout tempfile,'</table> <p>'
  262.  
  263.  
  264. /* ----- add comments information */
  265.  
  266. do jj=1 to nhidden
  267.    call lineout tempfile,hiddens.jj
  268. end /* do */
  269. call lineout tempfile,' <input type="hidden" name="entries" value="'||mm||'">'
  270. call lineout tempfile,' <input type="submit"> <input type="reset"> </form> '
  271.  
  272.  
  273. call lineout tempfile,' <hr> <h3> <A NAME="notes">Notes</A> </h3> <ul> <li> Usernames/passwords are stored in: 'userfile
  274. call lineout tempfile,' <li> To add more then 3 new names, just rerun this several times <br> or edit ' userfile 
  275. call lineout tempfile,' <li> Do you want to view a  more complete description of '
  276. call lineout tempfile,' <a href="/usercfg?TODO=SHOW_HEADER"> User information</a>?'
  277. call lineout tempfile,' <li> <em>Comments are NOT displayed </em>  <li> Case is ignored '
  278. call lineout tempfile,' <li> Use a <strong>* </strong> in the username or password to signify that <em>any entry is a match </em>'
  279. call lineout tempfile, ' <li> Entries with no <strong>host nickname</strong> will apply to all requests</ul> <br>'
  280.  
  281. call lineout tempfile,' <h3> A list of the <A NAME="hosts">current hosts</A> </h3>  <blockquote> '
  282.  
  283. ii=value(enmadd||'HOSTS.0',,'os2environment')
  284. if ii>0 then do
  285. call lineout tempfile,' <table> <th> IP address </th> <th> Host Nickname </th> <th> Data Directory </th> <tr> '
  286. do ll=1 to ii
  287.    wow=value(enmadd||'HOSTS.'||ll,,'os2environment')
  288.    parse var wow ip ',' hn ',' hdir
  289.    call lineout tempfile,' <td> ' ip  '</td> <td> ' hn ' </td> <td> ' hdir '</td> <tr> '
  290. end /* do */
  291. call lineout tempfile,' </table> </blockquote> '
  292. end
  293. else do
  294.   call lineout tempfile,' No HOSTS have been defined   </blockquote>'
  295. end
  296.  
  297. call lineout tempfile,' <p> <A HREF="#top">Return to the top of this form.</A>'
  298.  
  299. call lineout tempfile,'</body></html>'
  300. call lineout tempfile
  301.  
  302. foo=sref_expire_response(0.05,dosdir(tempfile))
  303.  
  304. 'file erase  type text/html name  ' tempfile
  305. return ' done '
  306.  
  307.  
  308. /* ********************** jump here to recrod changes */
  309. dochange:
  310.  
  311. parse upper var list foo 'ENTRIES=' nentries '&' .
  312. do ii1=1 to nentries
  313.    fillme.ii1.0=0
  314. end /* do */
  315.  
  316. do until list=""
  317.    parse var list aa '&' list
  318.    parse upper var aa avar '.' aind '=' aval
  319.    aval=packur(aval)
  320.    if abbrev(avar,'ENTRIES=')=1 then iterate
  321.    wow=fillme.aind.0+1
  322.    fillme.aind.0=wow
  323.    fillme.aind.wow.var=avar ; fillme.aind.wow.val=aval
  324.    select
  325.       when avar="COMMENT" then do
  326.           fillme.aind.type='COMMENT'
  327.           parse  var aa foo '=' aval
  328.           fillme.aind.wow.val=packur(aval)
  329.       end
  330.       when avar="USERNAME" then fillme.aind.type='USERNAME'
  331.       otherwise nop
  332.    end
  333. end /* do */
  334.  
  335. userfile=value(enmadd||'USER_FILE',,'os2environment')
  336. aa=fileread(userfile,'lins',,'E')
  337.  
  338. /* pull "header comments" */
  339. iat=0
  340. do until iat >= lins.0
  341.    iat=iat+1
  342.    if  abbrev(strip(lins.iat),';')  then do
  343.        newlines.iat=lins.iat
  344.    end  /* Do */
  345.    else do
  346.         leave
  347.    end
  348. end /* do -- iat is the first non header comment line  */
  349. iat=iat-1
  350.  
  351. do uu=1 to nentries
  352.    select
  353.       when fillme.uu.type='COMMENT' then do
  354.           iat=iat+1
  355.           newlines.iat=fillme.uu.1.val
  356.       end
  357.       when fillme.uu.type='USERNAME' then do
  358.           username=' ' ; password='*' ; hostname=' ' ; privs=' '
  359.           inhouse=' ' ; superuser=' '
  360.           do uu2=1 to fillme.uu.0
  361.              chk1=fillme.uu.uu2.var
  362.              vvv=fillme.uu.uu2.val
  363.              select
  364.                 when chk1='USERNAME' then USERNAME=vvv
  365.                 when chk1='PASSWORD' then password=vvv
  366.                 when chk1='PRIVS' then privs=vvv
  367.                 when chk1='HOSTNAME' then hostname=vvv
  368.                 when chk1='SUPERUSER' then superuser='SUPERUSER'
  369.                 when chk1='INHOUSE' then inhouse='INHOUSE'
  370.                 otherwise nop
  371.              end
  372.           end
  373.           if username<>' ' then do
  374.               iat=iat+1
  375.               newlines.iat=''
  376.               if hostname<>' ' then
  377.                   newlines.iat=hostname||'// '
  378.               newlines.iat=newlines.iat||username' ' password '  ' superuser ' ' inhouse ' ' privs
  379.           end
  380.       end
  381.       otherwise do
  382.             nop
  383.       end  /* Do */
  384.  
  385.   end                   /* select over type */
  386. end                     /* do over entries */
  387.  
  388. /* save to userfile.. but rename access_file first */
  389. foo=lastpos('.',userfile)
  390. if foo=0 then
  391.    acf1=userfile||'.'
  392. else
  393.    acf1=left(userfile,foo)
  394. do hi=1 to 999
  395.    try1=acf1||hi
  396.    if stream(acf1||hi,'c','query exists')='' then leave
  397. end /* do */
  398. foo=dosrename(userfile,try1)
  399. newlines.0=iat
  400. foo=filewrite(userfile,newlines,'R')
  401.  
  402.  
  403. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  404. call lineout tempfile, "<html><head><titLE> SRE-Filter: Changed list of Users</title>"
  405. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'"> '
  406.  
  407. call lineout tempfile,' <h2> The list of Users has  been changed </h2>'
  408. call lineout tempfile,' The list of Users has been saved to: ' userfile
  409. call lineout tempfile,' <p> The old version of 'userfile' has been moved to ' try1
  410. call lineout tempfile,' </body> </html> '
  411. call lineout tempfile
  412.  
  413. foo=value('SREF_REDO',1,'os2environment')
  414. 'FILE ERASE TYPE text/html NAME' tempfile
  415. return 'done change '
  416.  
  417.  
  418.  
  419.  
  420. return 'done change '
  421.